<?php

	class HelpAction extends Action {

		public function index(){
			$this->display('Help/index');
		}

		public function doGenerateInterface(){
			$arr_result=array(
				'status'=>0,
				'info'=>'失败');
			$main_link=$_REQUEST['mainlink'];
			// 前缀
			$link_depart=parse_url($main_link);
			log::write(var_export($link_depart,true),'link_depart');
			$pre_link=$link_depart['scheme'].'://'.$link_depart['host'].$link_depart['path'];
			log::write(var_export($pre_link,true),'pre_link');
			$link_para=$link_depart['query'];
			//解析参数
			$link_paras=D('Util')->getParams($link_paras);
			log::write(var_export($link_para,true),'link_para');
			log::write(var_export(D('Util')->pack_passport_api($pre_link, $link_paras, C('secret_key')),true),'link');
			//生成链接
			$arr_result['info']= D('Util')->pack_passport_api($pre_link, $link_paras, C('secret_key')); 
			$arr_result['status']=1;		

			$this->assign('arr_result',$arr_result);
			$this->display('Help/result');
		}

		public function doGetUserInfo(){
			// 获取用户id
			$userid =D('Help')->get_userid($_REQUEST['username']);

			// 根据用户id获取用户信息
			$url_get_userinfo='http://passport.fanli.com/api/admin/getUserInfo?';
			$params['userid']=$userid;

			$obj_result = D('Help')->get_url_result($url_get_userinfo,$params);
			$arr_result = $obj_result['data'][0];

			//获取用户安全等级
			$url_get_safelevel='http://passport.fanli.com/api/admin/getUserSafeLevel?';
			$obj_safelevel_result = D('Help')->get_url_result($url_get_safelevel,$params);
			$arr_safelevel_result=$obj_safelevel_result['data'];

			//获取用户的黑名单信息
			$url_get_blackinfo='http://passport.fanli.com/api/admin/getlockedinfo?';
			$obj_black_result = D('Help')->get_url_result($url_get_blackinfo,$params);
			$arr_balck_result=$obj_black_result['data'];

			//获取用户账户余额
			$url_get_accountbalance='http://passport.fanli.com/api/admin/userAccountBalance';
			$obj_accountbalance_result = D('Help')->get_url_result($url_get_accountbalance,$params);
			$arr_accountbalance_result=$obj_accountbalance_result['data'][$userid];

			$arr_result = array_merge($arr_result,$arr_safelevel_result,$arr_balck_result,$arr_accountbalance_result);

			$this->assign('arr_result',$arr_result);
			$this->display('Help/result');
		}

		public function do_update_password(){
			// 获取用户id
			$userid =D('Help')->get_userid($_REQUEST['username']);

			// 根据用户id获取用户信息
			$url_update_pwd='http://passport.fanli.com/api/admin/updatePassword?';
			$params['userid']=$userid;
			$params['userpassword']=$_REQUEST['pwd'];

			$obj_result = D('Help')->get_url_result($url_update_pwd,$params);
			$arr_result = (array)$obj_result;
			$this->assign('arr_result',$arr_result);
			$this->display('Help/result');
		}
	}